package com.ruoyi.web.xxj.contoller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.xxj.domain.School;
import com.ruoyi.web.xxj.service.ISchoolService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校名称Controller
 *
 * @author ruoyi
 * @date 2024-01-23
 */
@Api(tags = "学校信息管理")
@RestController
@RequestMapping("/xxj/school")
public class SchoolController extends BaseController {
    @Autowired
    private ISchoolService schoolService;

    /**
     * 查询学校名称列表
     */
    @ApiOperation("查询学校名称列表")
    @GetMapping("/list")
    public TableDataInfo list(School school) {
        startPage();
        List<School> list = schoolService.selectSchoolList(school);
        return getDataTable(list);
    }

    /**
     * 导出学校名称列表
     */
    @ApiOperation("导出学校名称列表")
    @Log(title = "学校名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, School school) {
        List<School> list = schoolService.selectSchoolList(school);
        ExcelUtil<School> util = new ExcelUtil<School>(School.class);
        util.exportExcel(response, list, "学校名称数据");
    }

    /**
     * 获取学校名称详细信息
     */
    @ApiOperation("获取学校名称详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(schoolService.selectSchoolById(id));
    }

    /**
     * 新增学校名称
     */
    @ApiOperation("新增学校名称")
    @Log(title = "学校名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody School school) {
        return toAjax(schoolService.insertSchool(school));
    }

    /**
     * 修改学校名称
     */
    @ApiOperation("修改学校名称")
    @Log(title = "学校名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody School school) {
        return toAjax(schoolService.updateSchool(school));
    }

    /**
     * 删除学校名称
     */
    @ApiOperation("删除学校名称")
    @Log(title = "学校名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(schoolService.deleteSchoolByIds(ids));
    }
}
